package com.example.mcdonaldapplication.info

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.example.mcdonaldapplication.R

class OrderAdapter(private val mutableList: MutableList<OrderInfo>)  : RecyclerView.Adapter<OrderAdapter.ViewHolder>() {

    class ViewHolder(itemView: View): RecyclerView.ViewHolder(itemView){
        val tvRestaurant: TextView = itemView.findViewById(R.id.tvRestaurant)
        val tvGoodsName: TextView = itemView.findViewById(R.id.tvGoodsName)
        val tvMoney: TextView = itemView.findViewById(R.id.tvMoney)
        val imageGood: ImageView = itemView.findViewById(R.id.imageGood)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.order_item,parent,false)
        return ViewHolder(view)
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val data = mutableList[position]
        holder.tvMoney.text = data.totalPrice
        holder.tvRestaurant.text = "麦当劳杭州临安万华广场餐厅"
        holder.tvGoodsName.text = data.goods[0].name
        if (data.goods[0].type == 0){
            holder.imageGood.setImageResource(R.drawable.hamburger0)
        } else if (data.goods[0].type == 1){
            holder.imageGood.setImageResource(R.drawable.hamburger1)
        }
    }

    override fun getItemCount(): Int {
        return mutableList.size
    }
}